package com.example.easyexcel.service.impl;

import com.alibaba.excel.EasyExcel;
import com.example.easyexcel.dao.DataIndexMapper;
import com.example.easyexcel.dto.DataIndex;
import com.example.easyexcel.listener.DataIndexListener;
import com.example.easyexcel.service.DataIndexService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;

@Service
@RequiredArgsConstructor
@Slf4j
public class DataIndexServiceImpl implements DataIndexService {

    private final DataIndexMapper dataIndexMapper;

    @Override
    public void importMetricExcel(MultipartFile file) {
        try (InputStream inputStream = file.getInputStream()) {
            EasyExcel.read(inputStream, DataIndex.class, new DataIndexListener(dataIndexMapper))
                    .sheet()
                    .doRead();
        } catch (IOException e) {
            throw new RuntimeException("t_data_index Excel 导入失败", e);
        }
    }
}
